/*
 * Logger.cpp
 *
 *  Created on: Aug 25, 2009
 *      Author: naveenoid
 */

#include "Logger.hpp"


namespace Octopus {

namespace ToolKit {

namespace Log {

using std::string;
using std::vector;
using std::fstream;
using std::ios_base;

Logger* Logger::logger;

Logger* Logger::getInstance(string str) {

//	if(logger==NULL)
//	{
	Logger *log = new Logger(str);
		printf("New Log initiated on %s\n", str.c_str());
//	}
	return(log);
}

void Logger::remove() {
	printf("Log is being closed");
	delete(this);
}


bool Logger::writeValues(int a, double b) {

	if(!isOpen)
	{
		printf("File Not Open\n");
		return(false);
	}
	else
	{
		file << a << ", " << b << "\n";
    }

	return(true);
//    cout << "Output " << lc << " records" << endl;
}


Logger::Logger(string temp) : fName(temp), file(temp.c_str(),ios_base::out), isOpen(false) {

//	ofstream outfile(fName.c_str(),ios::w);
    if (!file) {
    	printf("Failed to open Log file\n");
    	isOpen = false;
    }
    else {
    	isOpen = true;
    }

}

Logger::~Logger() {

	file.close();
}

}

}

}
